// pages/pastpage/pastpage.js
const request = require("../../utils/request");
import {imgUrlImg} from '../../config'
import {
  $await
} from '../../utils/util';
import {
  pastPageAPI
} from '../../api/public/index'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:1,
    pageSize:10,
    list:{
      videos:[]
    }
  },

  async getData(){
    let localChannelId = wx.getStorageSync('pid')
    let [err, res] = await $await(pastPageAPI.replayList({number:localChannelId,page:this.data.page,pageSize:this.data.pageSize}))
    if(res){
      res = res.map(item=>{
        return{
          ...item,
          time:this.formatime(item.time),
          cover:[`https://images.weserv.nl/?url=${imgUrlImg}${item.image}`]
        }
      })
      this.data.list.videos.push(...res)
      console.log(this.data.list.videos)
      this.setData({
        ["list.videos"]:this.data.list.videos
      })
    }
  },
  formatime(time){
      let date = new Date(parseInt(time) * 1000);
      const h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours())+ ':'
      const m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes())
      return h + m
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.hideHomeButton()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.data.page+=1
    this.getData()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})